docs: document non-UTF-8 encoding behavior in JSON output#355
Merged
jiegec merged 1 commit intolsof-org:masterfrom Mar 13, 2026
Merged
docs: document non-UTF-8 encoding behavior in JSON output#355jiegec merged 1 commit intolsof-org:masterfrom
jiegec merged 1 commit intolsof-org:masterfrom
Conversation
Unix file names are arbitrary byte sequences and may contain bytes that are not valid UTF-8. The JSON output modes (-J/-j) pass such bytes through unchanged, producing output that is not strictly RFC 8259 conformant but preserves original file names. This is consistent with lsfd(1), ip(8) -j, and other Linux tools. Document this behavior in the man page (Lsof.8), docs/options.md, docs/tutorial.md, and add a source comment on json_puts_escaped(). Closes lsof-org#354
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lsof.8) under-J/-jflags-J/-joptions with UTF-8 note todocs/options.mddocs/tutorial.mdwith full JSON section including encoding caveatjson_puts_escaped()insrc/print.cexplaining the trade-offMotivation
As noted by @stephane-chazelas in #353 and tracked in #354: Unix file names are arbitrary byte sequences and may contain bytes that are not valid UTF-8. The JSON output modes (
-J/-j) pass such bytes through unchanged, producing output that is not strictly RFC 8259 conformant but preserves original file names. This is the same approach taken bylsfd(1),ip(8) -j,systemctl --output=json, and other Linux tools.This behavior is worth documenting so users know what to expect and how to handle it if strict UTF-8 is required (e.g.
iconvor Python'ssurrogateescape).See https://unix.stackexchange.com/questions/757832/ for background.
Closes #354